using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Collections.ObjectModel;

namespace ConsoleWindow
{
	public partial class MainForm : Form
	{
    public class Employee
    {
      public string Name { get; set; }
      public int Number { get; set; }
    }
    public class ReadOnlyEmps : ReadOnlyCollection<Employee>, INotifyPropertyChanged
    {
      public ReadOnlyEmps():base(null) { }
      #region INotifyPropertyChanged Members

      public event PropertyChangedEventHandler PropertyChanged;

      #endregion
    }
    public class Doc
    {
      List<Employee> emps;
      int count;
      public Doc()
      {
        count = 3;
        emps = new List<Employee>()
        {
          new Employee(){Name="name1",Number=1},
          new Employee(){Name="name2",Number=2}
        };
      }
      public void Change()
      {
        emps.Add(new Employee() { Name = "name"+count, Number = count });
        ++count;
        if (OnChange != null)
          OnChange(this, EventArgs.Empty);
      }
      public event EventHandler OnChange;
      public ReadOnlyCollection<Employee> Employees { get { return new ReadOnlyCollection<Employee>(emps); } }
    }
    Doc doc;
		public MainForm()
		{
      doc = new Doc();
			InitializeComponent();
      dataGridView1.DataSource = doc.Employees;
      doc.OnChange += delegate
      {
        dataGridView1.DataSource = doc.Employees;
      };
      button2.Click += delegate
      {
        doc.Change();
      };
    }

		private void button1_Click(object sender, EventArgs e)
		{
			new CLRDependsForm().Show();
		}

		private void QuitButton_Click(object sender, EventArgs e)
		{
			Close();
		}
	}
}